#pragma once

#include "Globals.h"
#include "Debugger.h"
#include <vector>

class Object;

typedef std::vector<Object*> ObjectArray;

class Object
{
public:
	explicit Object(Object* parent = NULL);
	virtual ~Object();

	Object* GetParent() const { return m_parent; }
	const ObjectArray& Children() const { return m_children; }

#ifdef _DEBUG
	virtual void DumpSelf(Debugger& debugger);
	virtual void CheckSelf();
#endif // _DEBUG

protected:
	virtual void ChildInserted(Object* child);
	virtual void ChildRemoving(Object* child);
	virtual void DestroyChildren();

private:
	Object(const Object&);
	Object& operator= (const Object&);

	Object* m_parent;
	ObjectArray m_children;
};

class ObjectFactory
{
public:
	virtual ~ObjectFactory() {}
	virtual Object* CreateInstance(Object* Parent) = 0;
};

template <class T>
class TemplatedObjectFactory : public ObjectFactory
{
public:
	virtual Object* CreateInstance(Object* Parent) 
	{
		return new T(Parent);
	}
};